<?php

namespace App\Http\Resources\OpenShop\ExpireShop;

use App\Http\Resources\BaseResource;
use App\Models\Workflow\WorkflowOrderModel;
use Illuminate\Http\Request;

class FrontExpireShopListResource extends BaseResource
{

    /**
     * @param Request $request
     * @return array
     */
    public function toArray($request): array
    {
        $shopDetail    = $request->rmsShopCollection->where("shopCode", $this->shopCode)->first();
        $shopName      = vsprintf("%s %s", [
            attributeGet($shopDetail, "shopCode", ""),
            attributeGet($shopDetail, "name", "")
        ]);
        $addressPrefix = attributeGet($shopDetail, "addressPrefix", "");
        return [
            "orderNo"                 => $this->orderNo,
            "workOrderNo"             => $this->workOrderNo,
            "contractStartTime"       => $this->contractStartTime,
            "formatContractStartTime" => formatDateYmd($this->contractStartTime),
            "contractEndTime"         => $this->contractEndTime,
            "formatContractEndTime"   => formatDateYmd($this->contractEndTime),
            "username"                => attributeGet($this, "mainProcessRel.userIdentityCardRel.name", null),
            "shopName"                => $shopName,
            "addressPrefix"           => $addressPrefix,
            "statusText"              => WorkflowOrderModel::STATUS_TEXT[$this->workflowOrderRel->status] ?? "",
            "nodeStatusText"          => $this->workflowOrderRel->nodeDefineStatusText()
        ]; // TODO: Change the autogenerated stub
    }
}
